package com.ewhale.feitengguest.ui.user.mine.adapter;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import com.ewhale.feitengguest.R;
import com.ewhale.feitengguest.dto.WalletLogDto;
import com.simga.library.adapter.MBaseAdapter;

import java.util.List;

import androidx.core.content.ContextCompat;

import butterknife.BindView;
import butterknife.ButterKnife;

public class BillAdapter extends MBaseAdapter<WalletLogDto> {


    public BillAdapter(Context context, List<WalletLogDto> data) {
        super(context, data, R.layout.item_bill);
    }

    @Override
    protected void newView(View convertView, int position) {
        convertView.setTag(new ViewHolder(convertView));
    }

    @Override
    protected void holderView(View convertView, WalletLogDto itemObject, int position) {
        ViewHolder holder = (ViewHolder) convertView.getTag();
        if (itemObject.getAmount() > 0) {
            holder.mTvPrice.setText("+" + itemObject.getAmount());
        } else {
            holder.mTvPrice.setText(String.valueOf(itemObject.getAmount()));
        }
        if (itemObject.getType() == 1) {
            holder.mTvTitle.setText("任务佣金");
            holder.mTvPrice.setTextColor(ContextCompat.getColor(mContext, R.color.main_color));
        } else if (itemObject.getType() == 2) {
            holder.mTvTitle.setText("提现金额");
            holder.mTvPrice.setTextColor(ContextCompat.getColor(mContext, R.color.main_color));
        } else if (itemObject.getType() == 3) {
            holder.mTvTitle.setText("徒弟完成任务佣金");
            holder.mTvPrice.setTextColor(ContextCompat.getColor(mContext, R.color.text_333333));
        } else if (itemObject.getType() == 4) {
            holder.mTvTitle.setText("每日签到");
            holder.mTvPrice.setTextColor(ContextCompat.getColor(mContext, R.color.text_333333));
        } else if (itemObject.getType() == 5) {
            holder.mTvTitle.setText("提现失败");
            holder.mTvPrice.setTextColor(ContextCompat.getColor(mContext, R.color.text_333333));
        } else if (itemObject.getType() == 6) {
            holder.mTvTitle.setText("徒孙完成任务佣金");
            holder.mTvPrice.setTextColor(ContextCompat.getColor(mContext, R.color.text_333333));
        }
        holder.mTvTixianType.setText(itemObject.getCauseContent());
        holder.mTvTime.setText(itemObject.getCreateTime());
    }

    class ViewHolder {
        @BindView(R.id.tv_title)
        TextView mTvTitle;
        @BindView(R.id.tv_time)
        TextView mTvTime;
        @BindView(R.id.tv_tixian_type)
        TextView mTvTixianType;
        @BindView(R.id.tv_price)
        TextView mTvPrice;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
